

#import "WBNetworking.h"
#import <AFNetworking/AFNetworking.h>

static AFHTTPSessionManager *mgr;
@implementation WBNetworking


//当使用这个类，调用这个方法
+(void)initialize{
    //初始化会话管理者
    mgr = [AFHTTPSessionManager manager];
    //设置afn可以接受的类型数据
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    
}



/**
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    请求成功之后的回调
 *  @param failure    请求失败之后的回调
 */

+ (void)GET:(NSString *)URLString
 parameters:(id)parameters
    success:(void (^)(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject))success
    failure:(void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure{
    //使用afn网络请求
    [mgr GET:URLString parameters:parameters progress:nil success:success failure:failure];
    
}
+ (void)POST:(NSString *)URLString parameters:(id)parameters
     success:(void (^)(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject))success
     failure:(void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure{
  [mgr POST:URLString parameters:parameters progress:nil success:success failure:failure];

}

//声明一个 向服务器上传的 类方法
+ (void)POST:(NSString *)URLString parameters:(id)parameters token:(NSString *)token
     success:(void (^)(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject))success
     failure:(void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure{
     [mgr.requestSerializer setValue:token forHTTPHeaderField:@"token"];
//    mgr.requestSerializer = [AFJSONRequestSerializer serializer];
//    [mgr.requestSerializer setValue:@"token" forHTTPHeaderField:token];
    
    [mgr POST:URLString parameters:parameters progress:nil success:success failure:failure];
   

}


@end
